/**
 *
 */
package com.kgcx.coupon.rabbitmq.consumer;

import java.util.Date;
import javax.annotation.Resource;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.kgcx.coupon.domain.UserRelation;
import com.kgcx.coupon.dto.UserRelationDto;
import com.kgcx.coupon.service.UserPullNewService;
import lombok.extern.slf4j.Slf4j;
/**
 * 新人策略以及老用户每次领用赠送 登录接收
 * @author qinze
 *
 */
@Component
@Slf4j
public class NewStrategyListener {

	@Resource
	private UserPullNewService userPullNewService;

	//@RabbitListener(queues = "kgcxNewStrategyQueue", errorHandler = "custRabbitListenerErrorHandler")
	public void processCouponStatus(String json) {
		try {
			log.info("新人策略以及老用户每次领用赠送json = {}",json);
			UserRelationDto userRelationDto = JSONObject.parseObject(json, UserRelationDto.class);
			if (null != userRelationDto.getUserId() && userRelationDto.getUserId() > 0) {
				UserRelation userRelation = new UserRelation();
				userRelation.setActivationTime(new Date());
				userRelation.setRegisterTime(new Date());
				userRelation.setCoverUserId(userRelationDto.getCoverUserId());
				userRelation.setUserId(userRelationDto.getUserId());
				userPullNewService.inserUserPullNew(userRelation);
			}
		} catch (Exception e) {
			log.error("json:" + json + "---invoke error", e);
		}
	}
}
